package com.jufanshare.myblog.service.task;

import com.jufanshare.myblog.entity.Record;
import com.jufanshare.myblog.service.record.RecordService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * 作用：
 * 作者：Tiddler
 * 时间：2019/2/10 13：04
 * 类名： RecordClearTask
 **/
@Component
@EnableScheduling
public class RecordClearTask {
    private Log log= LogFactory.getLog(RecordClearTask.class);
    @Autowired
    private RecordService recordService;
    /**
     * 每天凌晨清空每日记录
     */
    @Scheduled(cron = "0 0 0 * * ?")
    public void run(){
        log.info("每日凌晨任务执行【独立IP页面访问记录】【重置密码验证码发送次数】【注册验证码发送次数】");
        //清空pv访问量记录
        Record record1=new Record();
        record1.setRecordtype("pvnumber");
        recordService.clearRecord(record1);
        //清空重置密码验证码发送次数记录
        Record record2=new Record();
        record2.setRecordtype("reset_email_code_record");
        recordService.clearRecord(record2);
        //清空注册发送邮箱验证码次数记录
        Record record3=new Record();
        record3.setRecordtype("register_email_code_record");
        recordService.clearRecord(record3);

    }
}
